import actionTypes from './actionTypes'

// 2.获取actiontype
const handleSeeting = (data) => {
    return {
        type: actionTypes.SETTING_THEME,
        payload: {
            data
        }
    }
}

// 设置成功之后的请求
const seetingSuccess = (data) => {
    return {
        type: actionTypes.SEETING_THEME_SUCCESS,
        payload: {
            data
        }
    }
}

export const seetingHandle = (data) => {
    return dispatch => {
        // 派送actiontype
        dispatch(handleSeeting(data))
        // 发送异步请求
        getSomeData()
            .then(res => {
                // 再次派送actiontypes
                dispatch(seetingSuccess(res))
            })
    }
}

// 模拟一个promise
const getSomeData = () => {
    return new Promise((res, rej) => {
        setTimeout(() => {
            res({
                id: '1',
                name: 'zhangshan',
                sex: 'nan',
                age: 12
            })
        }, 2000)
    })
}
// 减法的actiontype
const subType = (data) => {
    return {
        type: actionTypes.,
        payload: {
            data
        }
    }
}

// 加法的actiontype
const addType = (data) => {
    return {
        type: actionTypes.ADD,
        payload: {
            data
        }
    }
}

// 加法
export const addCount = (nums = 10) => {
    return addType(nums);
}

// 减法
export const sub = (nums = 5) => {
    return subType(nums);
}